﻿Ext.define('app.prm.detail.SelectTeam',
{
    extend: 'Ext.window.Window',
    border: true,
    title: '添加成员',
    width: 750,
    modal: true,
    shadow: true,
    bodyStyle: 'padding:3px',
    height: 600,
    layout: 'border',
    projectId: 0,
    initComponent: function () {
        var me = this;

        me.userItem = Ext.create("app.ux.UserSelector", { region: 'center' });

        this.items = [
            {
                region: 'north',
                height: 60,
                bodyStyle: 'padding:10px',
                border: false,
                layout: 'fit',
                items: [
                    me.getProjectRole()
                ]
            },
            me.userItem
        ];
        this.buttons = [
            {
                text: '保存',
                handler: function () { this.saveUsers(); }, scope: this
            },
            {
                text: '取消',
                handler: function () { this.close(); }, scope: this
            }
        ];
        me.callParent();
    },
    listeners: {
        afterrender: function (me) {
            App.AjaxGet('/api/services/app/projectRole/GetAll', function (data) {
                console.log(data);
                for (var i = 0; i < data.result.length; i++) {
                    var record = data.result[i];
                    var radio = new Ext.form.field.Radio({ boxLabel: record.roleName, name: 'projectRole', inputValue: record.id });
                    me.getProjectRole().add(radio);
                }
            });
        }
    },
    getProjectRole: function () {
        if (!this.prmRole) {
            this.prmRole = new Ext.form.RadioGroup(
            {
                fieldLabel: '项目成员',
                column: 5,
                items: []
            });
        }
        return this.prmRole;
    },
    saveUsers: function () {
        var me = this;

        var us = me.userItem.getValue();
        var check = me.getProjectRole().getChecked()[0];
        App.AjaxPost('/api/services/app/project/SetProjectTeam', { ProjectId: me.projectId, RoleId: check.inputValue, Users: us }, function (data) {
            me.fireEvent("savesuccess");
        });
    }
});